<?php
class file
{
	private $addr;

	function __construct($addr,$backup = false)
	{
		$this->addr = $addr;
	}
	
	function read()
	{
		$fp = @fopen($this->addr, 'r');
		while ( ($buf=fread( $fp, 8192 )) != '' ) {
	    $cont .= $buf;
		}
		@fclose($fp);
		return $cont;
	}
	
	function righe()
	{
		return file($this->addr);
	}
	
	function write($what,$method = false)
	{
		if($method) $mode = $method;
		else $mode = 'w';
		$fp = @fopen($this->addr, $mode);
		@fwrite($fp, $what);
		@fclose($fp);
	}
	
	function erase()
	{
		unlink($this->addr);
	}
	
	function load_array()
	{
		if(file_exists($this->addr))
		{
			$lines = @file($this->addr);
			$contenuto = "";
			foreach($lines as $line_num => $line)
				$contenuto .= $line;
			return @unserialize($contenuto);
		}	
		return false;
	}

	function save_array($array)
	{
		if(file_exists($this->addr))
			@unlink($this->addr);
			
		if(is_array($array))
		{
			$fp = @fopen($this->addr, 'a');
			@fwrite($fp, @serialize($array));
			@fclose($fp);
		}
	}
	
	function replace($stringa,$stringa2)
	{
		$new = str_replace($stringa,$stringa2,$this->read());
		$this->write($new);
	}
}
?>